package com.group3.group3.organ.service.impl;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Tom
 * @Date: 2022/05/19/16:38
 * @Description:
 */

import com.group3.group3.mybatis.flexigrid.PadingRstType;
import com.group3.group3.mybatis.flexigrid.PagingBean;
import com.group3.group3.mybatis.ztree.ZtreeEntity;
import com.group3.group3.organ.entity.OrganEntity;
import com.group3.group3.organ.repository.OrganDao;
import com.group3.group3.organ.service.OrganService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 *@ClassName OrganServiceImpl
 *@Description
 *@Author 王琛
 *@Date 2022/5/19 16:38
 @Version 1.0
 */
@Service("organService")
public class OrganServiceImpl implements OrganService {
    @Resource
    private OrganDao organDao;

    @Override
    public PadingRstType<OrganEntity> select(PagingBean paging) {
        PadingRstType<OrganEntity> padingRstType = new PadingRstType<>();
        padingRstType.setPage(paging.getPage());
        List<OrganEntity> list = organDao.select(paging);
        Integer total = organDao.Total();
        padingRstType.setRawRecords(list);
        padingRstType.setTotal(total);
        padingRstType.putItems();
        return padingRstType;
    }

    @Override
    public OrganEntity selectById(String organUuid) {
        return organDao.selectById(organUuid);
    }

    @Override
    public void delete(String organUuid) {
        organDao.delete(organUuid);
    }

    @Override
    public void insert(String organUuid, String organName, String modifierid, String modtime, String description) {
        organDao.insert(organUuid, organName, modifierid, modtime, description);
    }

    @Override
    public void update(String organName, String description, String organUuid) {
        organDao.update(organName, description, organUuid);
    }

    @Override
    public List<OrganEntity> selectParent() {
        return organDao.selectParent();
    }

    @Override
    public List<ZtreeEntity> zTreeList(String organUuid) {
        List<ZtreeEntity> list = organDao.zTreeList();
        for (ZtreeEntity item : list) {
            if (organUuid.equals(item.getpId())) {
                item.setChecked(true);
            }
        }
        return list;
    }

    @Override
    public void updateById(String oId, String parentUuids) {
        String[] pIdArray = parentUuids.split(",");
        for (String pId : pIdArray) {
            organDao.updateById(oId, pId);
        }

    }
}